package com.wu.proxy.cglib;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import org.springframework.cglib.proxy.Enhancer;
        import org.springframework.cglib.proxy.MethodInterceptor;
        import org.springframework.cglib.proxy.MethodProxy;

        import java.lang.reflect.Method;

/**
 * @author wufei
 * @date 2018/1/15 16:08
 */
public class WaiMaiXiaoGe implements MethodInterceptor{

    private static final Logger logger = LoggerFactory.getLogger(WaiMaiXiaoGe.class);

    public Object getNewInstence(Class cls){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(cls);
        enhancer.setCallback(this);
        return enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        logger.info("接到订单");
        methodProxy.invokeSuper(o,objects);
        logger.info("开始送餐");
        return null;
    }

}
